<?php include("../../data/mysql.class.php")?>
<?php include("../../data/Function.php")?>
<?php include("../../data/wechat.class.php")?>
<?php include("../info.php") ?>
<?
    if(isset($_POST["Type"])){
        $Type=$_POST["Type"];
    }else{
        $Type="error";
    }
	$conn=new Mysql();
	switch($Type){
		case "delete":
		if($conn->query("delete from d_worker where id =".$_POST["id"])){
			echo 1;
			}else{
				echo 0;
				}
		break;
		case "up":
		$w_id=$_POST["w_id"];
		$w_name=$_POST["w_name"];
		$w_nichen=$_POST["w_nichen"];
		$w_mobile=$_POST["w_mobile"];
		$pwd=$_POST["w_psw"];
		$rspwd=substr(md5($pwd),8,16);
		$w_pic=$_POST["w_pic"];
            if($conn->query("insert into d_worker(w_id,w_name,w_nichen,w_mobile,w_pic,w_psw,istate,adate) values('$w_id','$w_name','$w_nichen','$w_mobile','$w_pic','$rspwd',1,'".now()."')")){

                echo 1;
            }else{
                echo 0;
            }
		break;
		case "update":
            $w_name=$_POST["w_name"];
            $w_nichen=$_POST["w_nichen"];
            $w_mobile=$_POST["w_mobile"];
            $w_pic=$_POST["w_pic"];
            $pwd=$_POST["w_psw"];
            $ow_psw=$_POST["ow_psw"];
		    $id=$_POST["id"];
		    $conn=new Mysql();
		if($pwd!=""){$rspwd=substr(md5($pwd),8,16);}else{$rspwd=$ow_psw;}
		if($conn->query("update d_worker set w_name='$w_name',w_nichen='$w_nichen',w_mobile='$w_mobile',w_pic='$w_pic',w_psw='$rspwd' where id=".$id)){
					
				echo 1;}else{
					echo "update d_worker set w_name='$w_name',w_nichen='$w_nichen',w_mobile='$w_mobile',w_pic='$w_pic',w_psw='$rspwd' where id=".$id;
					}
		break;
		case "checkstate":
			if($conn->query("update  d_worker set istate=".$_POST["isstate"]." where id =".$_POST["id"])){
			echo 1;
			}else{
				echo 0;
				}
		break;
		default:
		break;
		}
?>